package Operation;

import Book.Book;
import Book.Library;

import java.util.Scanner;

public class AddBook implements IOperation{
    @Override
    public void work(Library library) {
        System.out.println("增添图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名：");
        String name = scanner.nextLine();
        for (int i = 0; i < library.getSize(); i++) {
            if(library.getBook(i).getName().equals(name)){
                System.out.println("该书已经有了");
                return;
            }
        }
        if(library.getSize() == library.getCapacity()){
            library.enlargelist();
        }
        System.out.println("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入价格：");
        double price = scanner.nextInt();
        System.out.println("请输入种类：");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        library.setBook(library.getSize(), book);
        library.setSize(library.getSize() + 1);
        System.out.println("添加完成");
        ShowBook showBook = new ShowBook();
        showBook.work(library);
    }
}
